package org.mysfit.ctp4j.core.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.mysfit.ctp4j.infra.entity.SkData;
import org.springframework.stereotype.Service;

/**
 * 
 * @author long.gf
 * @since 2022-12-06
 *
 */
@Service
public class PloyHelper {
	
	public static Map<String, Map<String, Boolean>> timeMap = new HashMap<String, Map<String, Boolean>>();
	
	private boolean checkTime(SkData sk, Integer c ,Integer l) {
		String ftime = sk.getFtime();
		String fid = sk.getFid();
		String sec = ftime.substring(ftime.length()-2);
		int iSec = Integer.parseInt(sec);
		if(iSec/c != l) {
			return false;
		}
		String key = ftime.substring(0, ftime.length()-2) + ":"+ l;
		if(null == timeMap.get(fid)) {
			Map<String, Boolean> newMap = new HashMap<String, Boolean>();
			timeMap.put(fid, newMap);
		}
		Map<String, Boolean> m = timeMap.get(fid);
		if(null == m.get(key)) {
			m.put(key, true);
			return true;
		}
		return false;
	}
	
	public int checkPolyAK(SkData sk) {
		if(this.checkTime(sk, 5, 6)) {
			return -1; 
		}else if(this.checkTime(sk, 5, 8)) {
			return 1;
		}
		return 0;
	}
	
	public int checkPolyAP(SkData sk) {
		if(this.checkTime(sk, 5, 2)) {
			return  -1;
		}if(this.checkTime(sk, 5, 4)) {
			return  1;
		}
		return 0;
	}
}	
